import request from './wrapRequest';
/**
 * 接口分类
 * @param data 
 * @returns 
 */
export interface ApiDataProps{
    _id: string | null;
    categoryId?: string;
    categoryName: string;
    apiName: string;
    apiPath: string;
    apiType?: string;
    desc: string;
}
/**
 * 查询接口信息
 * @returns 
 */
export const fetchList = () => {
  return  request.get<ApiDataProps[]>(`/admin/user/api/data/list`);
}


/**
 * 查询接口数据信息
 * @returns 
 */
export const fetchApiDataList = (path: string) => {
  return  request.get(path);
}

/**
 * 根据接口id查询接口信息
 * @param id 
 * @returns 
 */
export const fetchApiInfo = (id: string) => {
    return  request.get<ApiDataProps>(`/admin/user/api/data/`+ id);
}

/**
 * 增加接口数据
 * @param data 
 * @returns 
 */
export const addApiData = (data: ApiDataProps) => {
  return  request.put<boolean>(data.apiPath, data);
}


/**
 * 更新接口数据
 * @param data 
 * @returns 
 */
export const updateApi = (data: ApiDataProps) => {
  return  request.post<boolean>(data.apiPath, data);
}

/**
 * 删除接口数据
 * @param data 
 * @returns 
 */
export const deleteApi = (data: ApiDataProps) => {
  return  request.delete<boolean>(data.apiPath  + "/" + data._id);
}